package com.swsc.solarverse.dao.mapper.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swsc.solarverse.common.mybatis.BasePlusMapper;
import com.swsc.solarverse.dao.entity.sys.CorporationStationDO;
import com.swsc.solarverse.model.CorporationQueryBO;
import com.swsc.solarverse.model.CorporationStationBO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 电站信息表 Mapper 接口
 * </p>
 *
 * @author AutoGenerator
 * @since 2022-02-24
 */
@Mapper
public interface CorporationStationMapper extends BasePlusMapper<CorporationStationDO> {

    /**
     * 查询用户关联电站信息
     * @param queryBo
     * @return
     */
    List<CorporationStationBO> listUserCorporationStations(@Param("queryBo")CorporationQueryBO queryBo);

    /**
     * 角色电站
     * @param queryBo
     * @return
     */
    List<CorporationStationBO> listRoleCorporationStations(@Param("queryBo")CorporationQueryBO queryBo);

    /**
     * 电站信息
     * @param queryBo
     * @return
     */
    List<CorporationStationBO> listCorporationStations(@Param("queryBo")CorporationQueryBO queryBo);

    /**
     *
     * @param queryBo
     * @return
     */
    List<CorporationStationBO> selectCorporationStations(@Param("queryBo")CorporationQueryBO queryBo);
    Page<CorporationStationBO> selectCorporationStations(@Param("queryBo")CorporationQueryBO queryBo, IPage<CorporationStationBO> page);

    @org.apache.ibatis.annotations.Select(value = {
            "<script>",
            "SELECT sc.id, sc.create_time, sc.create_by, sc.update_time, sc.update_by, sc.deleted, sc.version, sc.tenant_no, sc.organ_no, sc.organ_name, sc.organ_short_name, sc.organ_pno, sc.organ_type, sc.organ_level, sc.capacity, sc.longitude, sc.latitude, sc.icon, sc.state, sc.contact, sc.telephone, sc.mobilephone, sc.address, sc.remark, sc.province, sc.coordinates, scs.station_type, ",
            " scs.access_grid_time, scs.annual_use_hour, scs.models, scs.model_num, scs.module_of_string_row, scs.modules_of_sting, scs.module_power, scs.already_run_time, scs.area, scs.dip_angle, scs.remain_run_time, scs.vector_model, scs.run_time, scs.trial_run_time, scs.acreage, scs.altitude, scs.panorama",
            " FROM `sys_corporation` sc LEFT JOIN `sys_corporation_station` scs ON sc.tenant_no = scs.tenant_no AND sc.organ_no = scs.organ_no",
            "<where>",
            "<if test='queryBo.tenantNo != null'> AND sc.`tenant_no` = #{queryBo.tenantNo}</if>",
            "<if test='queryBo.organNo != null'> AND sc.`organ_no` = #{queryBo.organNo}</if>",
            "<if test='queryBo.organPno != null'> AND sc.`organ_pno` = #{queryBo.organPno}</if>",
            "<if test='queryBo.organName != null and queryBo.organName !=\"\"'> AND sc.`organ_name` like concat('%',#{queryBo.organName,jdbcType=VARCHAR},'%')</if>",
            "<if test='queryBo.state != null and queryBo.state !=\"\"'> AND sc.`state` = #{queryBo.state}</if>",
            "<if test='queryBo.stateNe != null and queryBo.stateNe !=\"\"'> AND sc.`state` != #{queryBo.stateNe}</if>",
            "<if test='queryBo.organType != null and queryBo.organType !=\"\"'> AND sc.`organ_type` == #{queryBo.organType}</if>",

            "<if test='queryBo.organNoIn != null and queryBo.organNoIn.size() > 0'> AND sc.`organ_no` IN ",
            "<foreach collection='queryBo.organNoIn' item='organNo' open='(' close=')' separator=',' index=''>#{organNo}</foreach>",
            "</if>",

            "<if test='queryBo.stationType != null and queryBo.stationType !=\"\"'> AND scs.`station_type` = #{queryBo.stationType}</if>",
            "<if test='queryBo.stationTypeNe != null and queryBo.stationTypeNe !=\"\"'> AND scs.`station_type` != #{queryBo.stationTypeNe}</if>",

            "<if test='queryBo.stationTypeIn != null and queryBo.stationTypeIn.size() > 0'> AND scs.`station_type` IN ",
            "<foreach collection='queryBo.stationTypeIn' item='stationType' open='(' close=')' separator=',' index=''>#{stationType}</foreach>",
            "</if>",

            "<if test='queryBo.province != null and queryBo.province !=\"\"'> AND sc.`province` = #{queryBo.province}</if>",
            "</where>",
            "</script>"
    })
    List<com.swsc.solarverse.model.CorporationStationBO> queryCorporationCorporation(@Param("queryBo") CorporationQueryBO queryBo);

    /**
     * 获取总得电站数量
     * @return
     */
    Integer getStationNum(@Param("organNoList") List<Integer> organNoList);

    /**
     * 组件数量
     * @return
     */
    Integer getModelNum(@Param("organNoList")List<Integer> organNoList);

    /**
     * 总装机容量
     * @return
     */
    Double getTotalInstallNum(@Param("organNoList")List<Integer> organNoList);

    /**
     * 逆变器数量，查询表solar_device_info
     * @return
     */
    Integer getInverterNum(@Param("organNoList")List<Integer> organNoList);

    /**
     * 组串数量
     * @return
     */
    Integer getStringNum(@Param("organNoList")List<Integer> organNoList);

    /**
     * 总发电量
     * @param organNoList
     * @return
     */
    Double getTotalPower(@Param("organNoList")List<Integer> organNoList);

    /**
     * 查询飞手数量
     * @param organNoList
     * @return
     */
    Integer getFlyHandNum(@Param("organNoList")List<Integer> organNoList);
}
